﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace SeparateProjects
{
    public partial class Pro_AdminGradeSearch : Form
    {
        SqlConnection coon = new SqlConnection(@"Data Source = DESKTOP-28VSNS5;Initial Catalog = Training_Project; 
                                                Uid = Lv; Pwd = 123456;");
        public Pro_AdminGradeSearch()
        {
            InitializeComponent();
        }
        #region  预加载年级信息
        /// <summary>
        /// 预加载年级
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Pro_Admin_GradeSearch_Load(object sender, EventArgs e)
        {
            var sql = string.Format(@"select -1 Stu_StuInfo_Grade,'-请选择-' Grede_Name union select * from Grade");
            SqlDataAdapter adp = new SqlDataAdapter(sql,coon);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            this.cho_Grade.DisplayMember = "Grede_Name";
            this.cho_Grade.ValueMember = "Stu_StuInfo_Grade";
            this.cho_Grade.DataSource = ds.Tables[0];
            var val = this.cho_Grade.SelectedValue;
        }
        #endregion
        #region  点击查看学生信息
        /// <summary>
        /// 点击事件，查看学生信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Search_Click(object sender, EventArgs e)
        {
            //获取年纪信息
            var Grade = this.cho_Grade.Text;
            //连接数据库
            string str = string.Format(@"select S.UserName,T.Stu_StuInfo_Name,T.Stu_StuInfo_Age,Sex_Name,
                                        G.Grede_Name,T.Stu_StuInfo_Card,T.Stu_StuInfo_Birthday,T.Stu_StuInfo_Address,S.Password
                                        from Stu_Login S
                                        inner join Stu_StuInfo T on(T.Sid = S.Sid)
                                        inner join Sex SE on(T.Stu_StuInfo_Sex= Se.Stu_StuInfo_Sex)
                                        inner join Grade G on(G.Stu_StuInfo_Grade = T.Stu_StuInfo_Grade)
                                        where G.Grede_Name = '{0}'",Grade);
            DataSet ds = new DataSet();
            SqlDataAdapter adp = new SqlDataAdapter(str, coon);
            adp.Fill(ds);
            DataTable dt = ds.Tables[0];
            this.dataGridView1.DataSource = dt;
            //是否允许自动创建列
            this.dataGridView1.AutoGenerateColumns = false;
            //不允许出现空行
            this.dataGridView1.AllowUserToAddRows = false;
            //整行选中
            this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //是否允许多选
            this.dataGridView1.MultiSelect = false;
        }
        #endregion
        #region  右键添加成绩信息
        /// <summary>
        /// 右键添加成绩
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddSearch_Click(object sender, EventArgs e)
        {
            int Number = Convert.ToInt32(this.dataGridView1.CurrentRow.Cells[0].Value);
            Pro_Admin_Increase_Score abc = new Pro_Admin_Increase_Score(Number);
            abc.Show();
        }
        #endregion
    }
}
